<template>
  <div>
    <div class="list">
      <div
        class="item"
        :class="{ active: activeVal === item.dictValue }"
        v-for="(item, index) in listData"
        :key="item"
        @click="hadnleClick(item, index)">
        <span class="icon"></span>
        {{ item.dictLabel }}
      </div>
    </div>
  </div>
</template>

<script setup>
const props = defineProps({
  listData: Array,
  modelValue: String,
})
const emit = defineEmits(['update:modelValue'])

// const activeVal = computed(() => props.modelValue)
const activeVal = ref(null)
watch(
  () => props.modelValue,
  (newVal) => {
    activeVal.value = newVal
  },
  { immediate: true }
)

function hadnleClick(item, index) {
  activeVal.value = item.dictValue
  emit('update:modelValue', item.dictValue)
}
</script>

<style scoped lang="scss">
.list {
  display: flex;
  .item {
    margin-right: 30px;
    cursor: pointer;
    padding: 0 7px;
    font-size: 14px;
    color: var(--elp-text-color-regular);
    .icon {
      background-image: url('@/assets/image/task/select-task.png');
      background-repeat: no-repeat;
      background-size: 100% 100%;
      width: 16px;
      height: 16px;
      display: inline-block;
      margin-right: 2px;
      vertical-align: text-bottom;
    }
  }
  .active {
    background: var(--elp-color-info-light-9);
    border-radius: 4px;
    color: var(--elp-color-primary);
    .icon {
      background-image: url('@/assets/image/task/select-tasked.png');
    }
  }
}
</style>
